package com.example.litehdfs.util;

import java.sql.Types;
import java.util.Collections;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.config.TemplateType;
import com.baomidou.mybatisplus.generator.config.rules.DateType;
import com.baomidou.mybatisplus.generator.config.rules.DbColumnType;
import com.baomidou.mybatisplus.generator.engine.BeetlTemplateEngine;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class MybatisGeneratorUtil {
	 
	 
	 
    public static void main(String[] args) {
    	String finalProjectPath = System.getProperty("user.dir");
    	
    	FastAutoGenerator.create("jdbc:mysql://localhost:3306/lite-hdfs?characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai&allowMultiQueries=true&useUnicode=true",
    			"root", "123456")
        .globalConfig(builder -> {
            builder.author("mading") // 设置作者
//                .enableSwagger() // 开启 swagger 模式
                .fileOverride() // 覆盖已生成文件
                .dateType(DateType.ONLY_DATE)
                .outputDir(finalProjectPath + "/src/main/java"); // 指定输出目录
            
        })
        .packageConfig(builder -> {
            builder.parent("com.example.litehdfs") // 设置父包名
//                .moduleName("system") // 设置父包模块名
            
            	.entity("model.db.gen")
            	.mapper("mapper.gen")
                .pathInfo(Collections.singletonMap(OutputFile.xml, finalProjectPath + "/src/main/resources/mapper/gen")); // 设置mapperXml生成路径
            
//            	.entity("model.db")
//            	.mapper("mapper")
//            	.pathInfo(Collections.singletonMap(OutputFile.xml, finalProjectPath + "/src/main/resources/mapper")); // 设置mapperXml生成路径
        })
        .strategyConfig(builder -> {
        	builder.mapperBuilder().enableMapperAnnotation();
        	builder.entityBuilder().enableLombok();
            builder.addInclude("hdfs_cluster","hdfs_file","hdfs_folder","hdfs_task","init_tenant_config","operation_record","tenant","tenant_config","user_file_relation"); // 设置需要生成的表名
//                .addTablePrefix("t_", "c_"); // 设置过滤表前缀
        })
        .templateEngine(new BeetlTemplateEngine()) // 使用Freemarker引擎模板，默认的是Velocity引擎模板
        .templateConfig(builder -> { 
        		builder.disable(TemplateType.SERVICE,TemplateType.SERVICE_IMPL,TemplateType.CONTROLLER);
        	})
        .execute();
 
    }
 
 
 
}
